﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Mvc;

namespace Microsoft.AspNetCore.Mvc
{
    public static class ActionResultFactory
    {
        public static JsonResult Return200() => Return200<object>(default);

        public static JsonResult Return200<T>(T data)
        {
            return new JsonResult(new MyResult<T>(200, "ok", data));
        }

        public static JsonResult Success() => Return200();
        public static JsonResult Success<T>(T data) => Return200(data);

        public static JsonResult Return400() => Return400<object>("fail", default);
        public static JsonResult Return400(string msg) => Return400<object>(msg, default);
        public static JsonResult Return400<T>(string msg, T data = default)
        {
            return new JsonResult(new MyResult<T>(400, msg, data));
        }
        public static JsonResult Fail(string msg) => Return400<object>(msg, null);
        public static JsonResult Fail<T>(string msg, T data) => Return400(msg, data);

        public static JsonResult ReturnOther<T>(int code, string msg = null, T data = default)
        {
            return new JsonResult(new MyResult<T>(code, msg, data));
        }
    }
}
